<template>
  <div class="documentlist_page">
    <div class="page_title">最近查看</div>
    <div class="page_list">
      <el-table :data="dataList" :show-header="false" style="width: 100%" @row-dblclick="tableRowDblclick">
        <el-table-column show-overflow-tooltip>
          <template #default="scope">
            <div class="table_item_box">
              <svg-icon :icon-class="selectSvgIcons(scope.row)" style="font-size: 26px; vertical-align: middle; margin-right: 6px"></svg-icon>
              <span>{{ scope.row.realName }}{{ scope.row.suffix ? '.' + scope.row.suffix : '' }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column v-if="isViewedTime" align="center">
          <template #default="scope">
            {{ moment(scope.row.viewedTime).format('YYYY-MM-DD HH:mm') }}
          </template>
        </el-table-column>
        <el-table-column width="120px">
          <template #default="scope">
            {{ formatSize(scope.row.size) }}
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script setup lang="ts">
import moment from 'moment'; // 时间转化
import { ref, onMounted, defineProps, getCurrentInstance } from 'vue';
const { proxy } = getCurrentInstance() as any;
const isViewedTime = ref(false);
import { ApiPerGetParentTreeNodeAll } from '@/api/personDoc/personDocApi';
import storage from '@/utils/local';

const props = defineProps({
  dataList: {
    type: Array,
    default() {
      return [];
    }
  }
});

/**icon转换 */
const selectSvgIcons = (v: any) => {
  return proxy.$yuUtils.selectSvgIcon(v);
};

const formatSize = (size: number) => {
  return proxy.$yuUtils.filterSizeUnit(size);
};

const tableRowDblclick = async (row: any) => {
  let oParam = {
    id: row.fileId,
    fileType: 0
  };
  const res = await ApiPerGetParentTreeNodeAll(oParam);
  let expandedKeys = res.data.map((item) => {
    let obj = {
      id: parseInt(item.id),
      label: item.realName
    };
    return obj;
  });
  storage.sessionSet('expandedKeys', JSON.stringify(expandedKeys));
  // sessionStorage.setItem('expandedKeys', JSON.stringify(expandedKeys));
  proxy.$router.push({ path: '/newUi/networkDisk/doc' });
  console.log('🚀 ~ tableRowDblclick ~ row:', row);
};

onMounted(() => {
  window.onresize = () => {
    let width = document.documentElement.clientWidth;
    if (width <= 1600) {
      isViewedTime.value = false;
    } else {
      isViewedTime.value = true;
    }
  };

  // 访问 dataList
  console.log('传递的值:', props.dataList);
});
</script>

<style scoped lang="scss">
// 文字几行隐藏
@mixin textOverflow($clamp) {
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: $clamp; //元素几行显示
  -webkit-box-orient: vertical;
}

.documentlist_page {
  width: 100%;
  overflow: auto;
  position: absolute;
  padding: 16px;
  .page_title {
    font-size: 15px;
    font-weight: bold;
    margin-bottom: 5px;
  }
  .page_list {
    width: 100%;
    height: 570px;
    overflow: auto;
    .table_item_box {
      padding: 3px;
      // display: flex;
      // align-items: center;
      // margin-bottom: 4px;
      cursor: pointer;
      border-radius: 2px;
    }
    .realName_class {
      width: 290px;
      font-size: 14px;
      color: #444444;
      height: 17px;
      @include textOverflow(1);
    }
    .el-table {
      background-color: rgba(0, 0, 0, 0) !important;
    }
    .el-table :deep(tr) {
      background-color: rgba(0, 0, 0, 0) !important;
    }
  }
}
</style>
